/**
 * Copyright (C) 2010 Telecom digital
 * Created by Sam Guo
 */
package org.achartengine.model;

import java.util.ArrayList;
import java.util.List;

/**
 * A series for the range category charts like the range bar.
 */
public class CandlestickCategorySeries extends CategorySeries
{
	/** The series values. */
	private List<Double>	mCloseValues	= new ArrayList<Double>();
	private List<Double>	mLowValues	= new ArrayList<Double>();
	private List<Double>	mHighValues	= new ArrayList<Double>();

	/**
	 * Builds a new category series.
	 * 
	 * @param title the series title
	 */
	public CandlestickCategorySeries(String title)
	{
		super(title);
	}

	/**
	 * Adds new values to the series
	 * 
	 * @param openValue the new openValue value
	 * @param closeValue the new closeValue value
	 * @param lowValue the new lowValue value
	 * @param highValue the new highValue value
	 */
	public void add(double openValue, double closeValue, double lowValue,
			double highValue)
	{
		super.add(openValue);
		mCloseValues.add(closeValue);
		mLowValues.add(lowValue);
		mHighValues.add(highValue);
	}

	/**
	 * Adds new values to the series.
	 * 
	 * @param category the category
	 * @param minValue the new minimum value
	 * @param maxValue the new maximum value
	 */
	public void add(String category, double openValue, double closeValue,
			double lowValue, double highValue)
	{
		super.add(category, openValue);
		mCloseValues.add(closeValue);
		mLowValues.add(lowValue);
		mHighValues.add(highValue);
	}

	/**
	 * Removes existing values from the series.
	 * 
	 * @param index the index in the series of the values to remove
	 */
	public void remove(int index)
	{
		super.remove(index);
		mCloseValues.remove(index);
		mLowValues.remove(index);
		mHighValues.remove(index);
	}

	/**
	 * Removes all the existing values from the series.
	 */
	public void clear()
	{
		super.clear();
		mCloseValues.clear();
		mLowValues.clear();
		mHighValues.clear();
	}

	/**
	 * Returns the open value at the specified index.
	 * 
	 * @param index the index
	 * @return the open value at the index
	 */
	public double getOpenValue(int index)
	{
		return getValue(index);
	}

	/**
	 * Returns the close value at the specified index.
	 * 
	 * @param index the index
	 * @return the close value at the index
	 */
	public double getCloseValue(int index)
	{
		return mCloseValues.get(index);
	}

	/**
	 * Returns the low value at the specified index.
	 * 
	 * @param index the index
	 * @return the low value at the index
	 */
	public double getLowValue(int index)
	{
		return mLowValues.get(index);
	}

	/**
	 * Returns the high value at the specified index.
	 * 
	 * @param index the index
	 * @return the high value at the index
	 */
	public double getHighValue(int index)
	{
		return mHighValues.get(index);
	}

	/**
	 * Transforms the range category series to an XY series.
	 * 
	 * @return the XY series
	 */
	public XYSeries toXYSeries()
	{
		XYSeries xySeries = new XYSeries(getTitle());
		int length = getItemCount();
		for (int k = 0; k < length; k++)
		{
			xySeries.add(k + 1, getOpenValue(k));
			xySeries.add(k + 1, getCloseValue(k));
			xySeries.add(k + 1, getLowValue(k));
			xySeries.add(k + 1, getHighValue(k));
		}
		return xySeries;
	}
}
